package com.travelplanning.admin.config;


import cn.hutool.jwt.JWTUtil;
import com.fasterxml.jackson.core.JsonGenerator;
import com.travelplanning.admin.common.interceptor.JWTInterceptor;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;


import java.util.List;

/**
 * 配置类，注册web层相关组件
 */
@Configuration
@Slf4j
public class WebMvcConfiguration implements WebMvcConfigurer {
    @Resource
    private StringRedisTemplate stringRedisTemplate;



    @Override
    public void addInterceptors(InterceptorRegistry registry) {

        registry.addInterceptor(new JWTInterceptor(stringRedisTemplate))
                .addPathPatterns("/api/travel-planning/v1/user/**")
                .addPathPatterns("/api/travel-planning/v1/content/**")
                .addPathPatterns("/api/travel-planning/v1/comment/**")
                .addPathPatterns("/api/travel-planning/v1/order/**")
                .excludePathPatterns("/api/travel-planning/v1/user/login")
                .excludePathPatterns("/api/travel-planning/v1/user/register");

    }


}
